/*
 * Request.h
 *
 *  Created on: Feb 6, 2010
 *      Author: Jamie LaPointe
 */

#ifndef REQUEST_H_
#define REQUEST_H_

#include "Types.h"
#include <cstdlib>
#include <cstring>

namespace ProducerConsumer
{

namespace Common
{

class Request
{
public:
   Bool8 isValid;
   Bool8 isNullTerm;
   Int32 reqLength;
   Char8 * req;

   Request() :
      isValid(false), isNullTerm(false), reqLength(0), req(0)
   {
   }

   Request(const Request & rhs) :
      isValid(false), isNullTerm(false), reqLength(0), req(0)
   {
      if (req != 0)
      {
         free(req);
      }
      copy(rhs);
   }

   Request & operator=(const Request & rhs)
   {
      if (&rhs != this)
      {
         if (req != 0)
         {
            free(req);
         }
         copy(rhs);
      }
      return *this;
   }

   ~Request()
   {
      if (req != 0)
      {
         free(req);
      }
      req = 0;
   }

private:
   inline void copy(const Request & rhs)
   {
      isValid = rhs.isValid;
      isNullTerm = rhs.isNullTerm;
      reqLength = rhs.reqLength;
      req = (Char8 *) malloc(reqLength * sizeof(Char8));
      strcpy(req, rhs.req);
   }
}; // class Request

} // namespace Common

} // namespace ProducerConsumer

#endif /* REQUEST_H_ */
